﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Genuilder.Extensibility.Tests
{
	[TestClass]
	public class CodeRepositoryTest
	{
		[TestMethod]
		public void ShouldTrackCodeItem()
		{
			MockCodeRepository repository = new MockCodeRepository();
			bool trackItem = false;
			repository.CodeItemCreated += (s, c) => trackItem = true;
			repository.Histories.Add(new CodeItemHistory("file"));
			repository.Initialize();
			Assert.IsTrue(trackItem);
		}

		
		[TestMethod]
		public void ShouldFireModifiedCodeItem()
		{
			MockCodeRepository repository = new MockCodeRepository();
			bool itemModified = false;
			
			repository.Histories.Add(new CodeItemHistory("file")
			{
				Modified = true
			});
			repository.CodeItemCreated += (s, i) =>
			{
				if(i.Name == "file")
					i.ContentChanged += (c) => itemModified = true;
			};
			repository.Initialize();
			Assert.IsTrue(itemModified);
		}

		[TestMethod]
		public void ShouldFireNewStateCodeItem()
		{
			MockCodeRepository repository = new MockCodeRepository();
			bool itemStateChanged = false;
			repository.Histories.Add(new CodeItemHistory("file")
			{
				NewState = CodeItemState.Deleted
			});
			repository.CodeItemCreated += (s, i) =>
			{
				itemStateChanged = true;
			};
			repository.Initialize();
			Assert.IsTrue(itemStateChanged);
		}
	}

}
